package com.train.daily.facade.admin;

import cn.hutool.core.bean.BeanUtil;
import com.train.common.group.AddGroup;
import com.train.common.group.EditGroup;
import com.train.common.group.QueryGroup;
import com.train.common.resp.CommonResp;
import com.train.common.resp.PageResp;
import com.train.daily.dto.station.DailyTrainStationAddOrEditDTO;
import com.train.daily.dto.station.DailyTrainStationPageDTO;
import com.train.daily.req.station.DailyTrainStationAddOrEditReq;
import com.train.daily.req.station.DailyTrainStationPageReq;
import com.train.daily.resp.station.DailyTrainStationPageResp;
import com.train.daily.service.DailyTrainStationService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * dailyTrainStation Facade 实现类
 * @author baitiaojun
 * @createDate 2025-03-01 14:35:49
 */
@RestController("adminDailyTrainStationFacade")
@RequiredArgsConstructor
@RequestMapping("/admin/train-station")
public class DailyTrainStationFacade {

    private final DailyTrainStationService dailyTrainStationService;

    @PostMapping("page")
    public CommonResp pageList(@RequestBody @Validated(QueryGroup.class) DailyTrainStationPageReq req) {
        DailyTrainStationPageDTO dailyTrainStationPageDTO = BeanUtil.copyProperties(req, DailyTrainStationPageDTO.class);
        PageResp<DailyTrainStationPageResp> pageResp = dailyTrainStationService.pageList(dailyTrainStationPageDTO);
        return CommonResp.ok(pageResp);
    }

    @PostMapping("add")
    public CommonResp add(@RequestBody @Validated(AddGroup.class) DailyTrainStationAddOrEditReq req) {
        DailyTrainStationAddOrEditDTO dailyTrainStationAddOrEditDTO = BeanUtil.copyProperties(req, DailyTrainStationAddOrEditDTO.class);
        dailyTrainStationService.addOrEditDailyTrainStation(dailyTrainStationAddOrEditDTO);
        return CommonResp.ok();
    }

    @PostMapping("edit")
    public CommonResp edit(@RequestBody @Validated(EditGroup.class) DailyTrainStationAddOrEditReq req) {
        DailyTrainStationAddOrEditDTO dailyTrainStationAddOrEditDTO = BeanUtil.copyProperties(req, DailyTrainStationAddOrEditDTO.class);
        dailyTrainStationService.addOrEditDailyTrainStation(dailyTrainStationAddOrEditDTO);
        return CommonResp.ok();
    }

    @DeleteMapping("remove/{id}")
    public CommonResp delete(@PathVariable("id") Long id) {
        dailyTrainStationService.remove(id);
        return CommonResp.ok();
    }
}
